//
//  ZYVisitorViewController.swift
//  CZ29WeiboZYH
//
//  Created by 沐颜澈 on 16/6/25.
//  Copyright © 2016年 muyanche. All rights reserved.
//

import UIKit

class ZYVisitorViewController: UITableViewController {
    
    //判断用户是否登录的标识
    let islogin: Bool = ZYUserAccountTools.sharedTools.isLogin
      //let islogin: Bool = false
    
    //----------设置访客视图的view---------------------全局属性
    var VisitorView: ZYVisitorView?
    
    override func loadView() {
        if islogin {
            //如果登录了就调用父类的登录方法
            super.loadView()
        } else {
            
            setupVisitorView()
        
        }
    }
    
    //MARK: - 设置访客视图的view
    func setupVisitorView() {
        
        
        
        //调用导航栏方法
        setupNav()
//        VisitorView
//        let visitorView = ZYVisitorView()
        VisitorView = ZYVisitorView()
//        visitorView.backgroundColor = RandomColor()
        
        VisitorView?.closure = { [weak self] in
            
            print("VisitorVC点击了")
            self?.loginClick()
        
        }
        
        view = VisitorView
        
    }
    
    //MARK: - 设置导航栏的登录注册按钮
    private func setupNav() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
    
    }
    
    //MARK: - 实现登录注册按钮的监听方法,弹出OAuth控制器
    @objc private func loginClick() {
        print("登录注册按钮点击")
        //弹出控制器
        let oauthVC = ZYOAuthViewController()
        let navc = UINavigationController(rootViewController: oauthVC)
        
        presentViewController(navc, animated:true, completion: nil)
        
        
        
    }
    

}















